strpos คือ คำสั่งสำหรับการค้นหาข้อความ ตัวอักษร หรือข้อมูลต่าง ๆ ที่เราต้องการจากตัวแปร หรือข้อความที่กำหนด
ภาพรวมของคำสั่ง strpos
1. ใช้คำสั่ง strpos([MESSAGE], [NEDDLE])
2. MESSAGE คือ ข้อความ หรือตัวแปรที่เราต้องการเข้าไปค้นหา
3. NEDDLE คือ ข้อความ หรือตัวแปรที่เราต้องการนำไปค้นหา
ตัวอย่างโปรแกรม
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?
$message = "Hello, AmplySoft";
$find = "AmplySoft";
if( strpos( $message, "AmplySoft" )) {
echo "พบข้อความ $find ในข้อความ $message";
} else {
echo "ไม่พบข้อความ $find ในข้อความ $message";
}
?>
</body>
</html>
ผลลัพธ์
พบข้อความ AmplySoft ในข้อความ Hello, AmplySoft